"""
进度 Request VO
"""

import utils.enum_utils as enum
from models import (
    ListRequestBase,
    QueryFieldBase,
    RequestBase,
)
from utils.data_utils.special import ObjectIdStr
from utils.validator_utils.pydantic_validator.field import (
    PathCharField,
    QueryCharField,
)


class ProcessPathField:
    """ 进度 | 路径 | 字段 """

    process_id: ObjectIdStr = PathCharField(..., title="进度 ID")


class ProcessDetailRequest(RequestBase):
    """ 进度 | 详情 | 请求 """

    process_id: ObjectIdStr = ProcessPathField.process_id


class ProcessListRequest(ListRequestBase):
    """ 进度 | 列表 | 请求 """

    # -------------------- 排序字段 --------------------
    sort_by_create_time: enum.MongoSortOrNone = QueryCharField(None, title="根据创建时间排序")
    sort_by_status: enum.MongoSortOrNone = QueryCharField(None, title="根据状态排序")
    sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序")

    # -------------------- 查询字段 --------------------
    status: enum.ProcessStatus | None = QueryCharField(None, title="状态")
    task: enum.ProcessTask | None = QueryCharField(None, title="任务类型")

    @classmethod
    def from_query(
        cls,
        page: int = QueryFieldBase.page,
        page_size: int = QueryFieldBase.page_size,
        sort_by_create_time: enum.MongoSortOrNone = QueryCharField(None, title="根据创建时间排序"),
        sort_by_status: enum.MongoSortOrNone = QueryCharField(None, title="根据状态排序"),
        sort_by_update_time: enum.MongoSortOrNone = QueryCharField(None, title="根据更新时间排序"),
        status: enum.ProcessStatus | None = QueryCharField(None, title="状态"),
        task: enum.ProcessTask | None = QueryCharField(None, title="任务类型"),
    ) -> "ProcessListRequest":
        return cls(
            page=page,
            page_size=page_size,
            sort_by_create_time=sort_by_create_time,
            sort_by_status=sort_by_status,
            sort_by_update_time=sort_by_update_time,
            status=status,
            task=task,
        )


class ProcessTerminateRequest(ProcessDetailRequest):
    """ 进度 | 终止 | 请求 """
